package sha256

import (
	"crypto/sha256"
	"encoding/hex"
)

// SHA256加密字符串, 64位
func GetSHA256Encode(data string, salt ...string) string {
	hash := sha256.New()
	// 加盐
	if salt != nil {
		for _, ele := range salt {
			hash.Write([]byte(ele))
		}
	}
	hash.Write([]byte(data))
	out := hash.Sum(nil)
	return hex.EncodeToString(out)
}

// SHA224加密字符串, 56位
func GetSHA224Encode(data string, salt ...string) string {
	hash := sha256.New224()
	// 加盐
	if salt != nil {
		for _, ele := range salt {
			hash.Write([]byte(ele))
		}
	}
	hash.Write([]byte(data))
	out := hash.Sum(nil)
	return hex.EncodeToString(out)
}